
using System.Net;
using System.Text.RegularExpressions;

namespace 百度必应搜索
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Search_baidu(string url)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                WebResponse response = request.GetResponse();
                Stream resStream = response.GetResponseStream();
                StreamReader sr = new StreamReader(resStream);
                string webInfo = sr.ReadToEnd();
                string webData = "";
                foreach (Match match in Regex.Matches(webInfo, @"[\u4E00-\u9FFF]+"))
                {
                    webData += match;
                }
                this.Invoke((MethodInvoker)delegate {
                    textBox2.Text = webData.Substring(0, Math.Min(200, webData.Length));
                });
            }
            catch (Exception) { }
        }
        // bing
        private void Search_bing(string url)
        {
            try
            {
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                WebResponse response = request.GetResponse();
                Stream resStream = response.GetResponseStream();
                StreamReader sr = new StreamReader(resStream);
                string webInfo = sr.ReadToEnd();
                string webData = "";
                foreach (Match match in Regex.Matches(webInfo, @"[\u4E00-\u9FFF]+"))
                {
                    webData += match;
                }
                this.Invoke((MethodInvoker)delegate {
                    textBox3.Text = webData.Substring(0, Math.Min(200, webData.Length));
                });
            }
            catch (Exception) { }
        }
    
    private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Task task_baidu = new Task(() => { Search_baidu("http://www.baidu.com/s?wd=" + textBox1.Text); });
                Task task_bing = new Task(() => { Search_bing("https://cn.bing.com/search?form=MOZTSB&pc=MOZI&q=" + textBox1.Text); });
                task_baidu.Start();
                task_bing.Start();
            }
            catch (Exception) { }
        }
    }
}
